package com.videomeetting.legend.videomeetting.activity.fragment;

import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;

import com.videomeetting.legend.videomeetting.R;
import com.videomeetting.legend.videomeetting.activity.adapater.FileChooseAdapater;
import com.videomeetting.legend.videomeetting.activity.bean.MessageEvent;
import com.videomeetting.legend.videomeetting.activity.layoutmanager.MyLinearLayoutManager;

import org.greenrobot.eventbus.EventBus;

/**
 * Created by legend on 18-7-1.
 */

public class FileChooseFragment extends DialogFragment {
    private FileChooseAdapater adapater;
    private String tag;

    public FileChooseAdapater getAdapater() {
        return adapater;
    }

    public void setAdapater(FileChooseAdapater adapater) {
        this.adapater = adapater;
    }

//        List<String> fileNames= Arrays.asList("2014-03-20-1103.mp4","2014-06-26-1489.mp4","2014-07-10-0026.mp4","2014-12-06-0398.mp4");
//    List<String> fileTimes = Arrays.asList("26","48","55","96");
//    List<String> fileLenghts = Arrays.asList("1032","2023","2688","5686");
//    List<String> fileCreateTimes = Arrays.asList("2018-7-1","2018-6-30","2018-6-30","2018-6-30");
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        getDialog().getWindow().addFlags(Window.FEATURE_NO_TITLE);
        View view = inflater.inflate(R.layout.fragment_file_choose, container,false);
        RecyclerView filesRv= (RecyclerView) view.findViewById(R.id.fragment_files_choose_rv);
//        FileChooseAdapater adapater = new FileChooseAdapater(getContext(),fileNames,fileTimes,fileLenghts,fileCreateTimes);
        MyLinearLayoutManager manager = new MyLinearLayoutManager(getContext());
        filesRv.setAdapter(adapater);
        adapater.setmOnItemClickListener(new FileChooseAdapater.OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                tag = getTag();
                //弹出框消失，将选择的文件名显示在输入框中。
                if (tag.equals("voicechoose")) {
                    EventBus.getDefault().post(new MessageEvent(2,adapater.getVideoBeans().get(position).getFilePath()));
                }
                if (tag.equals("filechose")) {
                    EventBus.getDefault().post(new MessageEvent(5,adapater.getVideoBeans().get(position).getName()));
                }
                if (tag.equals("home_filechose")){
                    EventBus.getDefault().post(new MessageEvent(6,adapater.getVideoBeans().get(position).getFilePath()));
                }
                dismiss();
            }
        });
        filesRv.setLayoutManager(manager);
        return view;
    }

}
